    package com.ymatou.iapi.productsnapshot.testcase;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.productsnapshot.parameter.GetProductSnapshotListBean;
import com.ymatou.iapi.productsnapshot.service.GetProductSnapshotListCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.mongo.SnapShotWapper;
import com.ymttest.utils.DiffUtil;
/**
*查询快照
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetProductSnapshotList{
	private static GetProductSnapshotListBean getproductsnapshotlistBean;
	private static GetProductSnapshotListCall getproductsnapshotlistCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询快照");
	}

	@Before
	public void caseUp() {
		getproductsnapshotlistBean=new GetProductSnapshotListBean();
		getproductsnapshotlistCall=new GetProductSnapshotListCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getproductsnapshotlistCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetProductSnapshotList_001() {
		Logger.start(true,"查询商品快照成功");
		try {
//			getproductsnapshotlistCall=new GetProductSnapshotListCall("snapshot");
			String pid="d34e1e0e-7f44-4f83-82b9-26a21d916dc1";
			getproductsnapshotlistBean.setAppId("autotest");
			getproductsnapshotlistBean.setProductId(pid);
			List<String> versionlist=new ArrayList<String>();
			versionlist.add("1.003");
			getproductsnapshotlistBean.setVersionList(versionlist);
			getproductsnapshotlistCall.setData(getproductsnapshotlistBean);
			getproductsnapshotlistCall.callService();			
			//{"Code":200,"Msg":"","BCode":0,"Data":{"requestSuccess":true,"errorCode":0,"errorMessage":null,"SnapshotList":[{"productId":"bda435e9-6da1-487a-8a51-f7ab952f5f94","productVersion":1.001,"title":"科西嘉岛快点见到你身边","introduction":"四季豆大家都觉得好激动顶焦度计","picList":["http://pic1.ymatou.com/G01/shangou/M00/2F/24/rBBlD1hXvGiAJLWyAAFexQcl87w443_40_71_n_w_o.jpg"],"validStart":null,"validEnd":null,"brandId":10779,"brandName":"","brandEnName":"Magdesians","masterCategoryId":1072,"masterCategoryName":"家居日用、宠物用品","categoryId":1079,"categoryName":"清洁用品","thirdCategoryId":1564,"thirdCategoryName":"清洁工具","catalogType":1,"deliveryMethod":2,"bondedArea":0,"productCode":"","localReturn":2,"noReasonReturn":false,"tariffType":0,"action":0,"description":"四季豆大家都觉得好激动顶焦度计","grade":"B","ownProduct":false,"weightUnit":0,"descPicList":["http://pic1.ymatou.com/G01/shangou/M00/2F/24/rBBlD1hXvGiAJLWyAAFexQcl87w443_40_71_n_w_o.jpg"],"sizePicList":[],"noticeText":null,"noticePicList":[],"sellerIntroText":null,"extraDeliveryType":0,"extraDeliveryFee":0.0,"sellerIntroPicList":[],"propertyList":null,"catalogList":[{"catalogId":"2582b3a0-bffc-4a34-801f-3529a760606e","price":50.0,"vipPrice":40.0,"newPrice":30.0,"weight":0.0,"propertyList":[{"name":null,"value":null,"picUrl":null}],"extraDelivery":false,"package":false,"preSale":false}],"templateList":null,"pspProduct":false,"freeShipping":false}]},"Trace":null}
			Logger.verifyEquals("200", getproductsnapshotlistCall.getString("Code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetProductSnapshotList_002() {
		Logger.start(true,"不输入版本id失败");
		try {
//			String pid="d34e1e0e-7f44-4f83-82b9-26a21d916dc1";
			getproductsnapshotlistBean.setAppId("autotest");
//			getproductsnapshotlistBean.setProductId(pid);
			List<String> versionlist=new ArrayList<String>();
			versionlist.add("1.003");
			getproductsnapshotlistBean.setVersionList(versionlist);
			getproductsnapshotlistCall.setData(getproductsnapshotlistBean);
			getproductsnapshotlistCall.callService();	
			Logger.verifyEquals("400", getproductsnapshotlistCall.getString("Code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetProductSnapshotList_003() {
		Logger.start(true,"输入多笔版本id查询快照成功");
		try {
			String pid="d34e1e0e-7f44-4f83-82b9-26a21d916dc1";
			getproductsnapshotlistBean.setAppId("autotest");
			getproductsnapshotlistBean.setProductId(pid);
			List<String> versionlist=new ArrayList<String>();
			versionlist.add("1.002");
			versionlist.add("1.003");
			getproductsnapshotlistBean.setVersionList(versionlist);
			getproductsnapshotlistCall.setData(getproductsnapshotlistBean);
			getproductsnapshotlistCall.callService();	
			Logger.verifyEquals("200", getproductsnapshotlistCall.getString("Code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	@Ignore
	public void Tc_GetProductSnapshotList_004() {
		Logger.start(true,"循环对比查询版本成功");
		try {
			SnapShotWapper ssw=new SnapShotWapper();
			DiffUtil df=new DiffUtil();
			df.setLogFile("GetProductSnapshotList.txt");
			
			
			List<String> ilist=new ArrayList<>();
			ilist.add("Msg");
			df.setIgnoreList(ilist);
			
			
			Map<String, String> m=new HashMap<>();
			m.put("Data.SnapshotList.ValidEnd","^.{19}");
			m.put("Data.SnapshotList.ValidStart","^.{19}");
			
			df.setPrecision(m);
			
			GetProductSnapshotListCall getproductsnapshotlistCall2=new GetProductSnapshotListCall("snapshot");
			ArrayList<Map> list = ssw.getProductVersionInfoLens(2000, null);
			getproductsnapshotlistBean.setAppId("autotest");
			for (Map map : list) {
				getproductsnapshotlistBean.setProductId(map.get("pid").toString());
				List<String> VersionList=new ArrayList<>();
				StringBuffer sb = new StringBuffer(map.get("ver").toString());
				sb.insert(sb.length()%3==0?3:sb.length()%3, ".");
				Logger.debug(sb);
				VersionList.add(sb.toString());
				getproductsnapshotlistBean.setVersionList(VersionList);
				getproductsnapshotlistCall.setData(getproductsnapshotlistBean);
				getproductsnapshotlistCall.callService();			
				getproductsnapshotlistCall2.setData(getproductsnapshotlistBean);
				getproductsnapshotlistCall2.callService();
				
				df.appendLogFile( "pid:"+map.get("pid").toString()+":ver:"+sb);
				
				df.compareJsonString(getproductsnapshotlistCall2.getReturnData(), getproductsnapshotlistCall.getReturnData());
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}